package com.pug.web.test;

import com.pug.mapper.user.UserMapper;
import com.pug.pojo.HotelUserCollect;
import com.pug.pojo.KssUser;
import com.pug.service.hotel.HotelUserCollectServiceImpl;
import com.pug.service.user.UserServiceImpl;
import com.pug.vo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * Author: lqm
 * create: 2022/3/22 14:28
 * Lover: lqx
 *
 * @see
 */
@RestController
@Slf4j
public class MyTestController {
    @Resource
    UserServiceImpl userService;
    @Resource
    HotelUserCollectServiceImpl hotelUserCollectService;
    @Resource
    UserMapper userMapper;
    @Resource
    StringRedisTemplate stringRedisTemplate;
    @GetMapping("/test")
    public void test(){
        userMapper.updateAvatarById(13800040004L,"abc.jpg");
    }
    @GetMapping("/test/test")
    public void test_1(){
        stringRedisTemplate.opsForValue().set("aaa","qixia");
        stringRedisTemplate.opsForValue().get("aaa");
    }
    @GetMapping("/test/a")
    public void test01(){
        Set<String> aa = stringRedisTemplate.keys("aa*");
    }
    //测试 redis实现分布式锁

    public void distributedLock(){
        stringRedisTemplate.opsForValue().set("name","lihua",1000);
    }

    //测试 redis实现消息队列

    //测试事务
    PlatformTransactionManager platformTransactionManager;
    JdbcTransactionManager jdbcTransactionManager=new JdbcTransactionManager();
    @Transactional(propagation = Propagation.REQUIRED)
    @PostMapping("/test/transactional")
    public void transactionTest(){
        HotelUserCollect userCollect=new HotelUserCollect(12L,10L,10L,new Date(),new Date());
        hotelUserCollectService.save(userCollect);
        throw new RuntimeException("呵呵");
    }

    public void aaa(){
        Order order = new Order();
        ThreadLocal threadLocal;
    }
    //测试rabbitmq
//    @RabbitListener(queues = "fanout_logon_queue")
//    public void logon(String message){
//        log.info("{}::成功注册",message);
//    }
    public static void main(String[] args) {
        HashMap<Integer,Integer> map=new HashMap<>();
        ArrayList<Integer> list=new ArrayList<>();
        Iterator<Integer> iterator = list.iterator();
    }
    @GetMapping("/test/testRedis")
    public void testRedis(){
        String lihua = stringRedisTemplate.opsForValue().get("lihua");
        System.out.println(lihua);
    }
 
}
